﻿using System;
using System.Linq.Expressions;

namespace TSharp.Core.Osgi
{
    /// <summary>
    /// 
    /// </summary>
    /// <author>
    /// tangjingbo
    /// </author>
    /// <remarks>
    /// tangj15 at 2012-5-4 13:13
    /// </remarks>
    public class RegAppEndAttribute : RegExtensionAttribute
    {
        private static readonly Type _IcleanType = typeof(IOsgiDispose);
        /// <summary>
        /// Initializes a new instance of the <see cref="RegAppEndAttribute"/> class.
        /// </summary>
        /// <param name="cleanType">Type of the clean.</param>
        public RegAppEndAttribute(Type cleanType)
        {
            if (!cleanType.IsAssignableFrom(cleanType))
                throw new ArgumentException(string.Format("类‘{0}’必须实现接口‘{1}'。", cleanType, _IcleanType));
            New = Expression.Lambda<Func<IOsgiDispose>>(Expression.New(cleanType)).Compile();
        }
        internal Func<IOsgiDispose> New;
    }
}